 
//随机生成数字
export function done(len, max) {
  var arr = [];
  var result = "";
  var count = 0;
  while (count < len) {
    var n = Math.floor(Math.random() * max + 1);
    if (arr.join().indexOf(n) == -1) {
      arr.push(n);
      count++;
    }
  }
  for (let index = 0; index < arr.length; index++) {
    result = result + arr[index];
  }
  return result;
}

//根据时间生成渠道编码
/**
* 查询当天日期
*/
export function TimeDate() {
  const timeOne = new Date()
  const year = timeOne.getFullYear()
  let month = timeOne.getMonth() + 1
  let day = timeOne.getDate()
  month = month < 10 ? '0' + month : month
  day = day < 10 ? '0' + day : day
  const NOW_MONTHS_AGO = `${year}-${month}-${day}`
  return NOW_MONTHS_AGO;
}

//utf时间转北京时间
export function convertUTCTimeToLocalTime(UTCDateString) {
  if (!UTCDateString) {
    return '-';
  }
  function formatFunc(str) {    //格式化显示
    return str > 9 ? str : '0' + str
  }
  var date2 = new Date(UTCDateString);     //这步是关键
  var year = date2.getFullYear();
  var mon = formatFunc(date2.getMonth() + 1);
  var day = formatFunc(date2.getDate());
  var hour = date2.getHours();
  var noon = hour >= 12 ? 'PM' : 'AM';

  hour = formatFunc(hour);
  var min = formatFunc(date2.getMinutes());
  var dateStr = year + '-' + mon + '-' + day + '   ' + hour + ':' + min;
  return dateStr;
}

//获取前三个月时间
export function GetMonA(num) {

  const dates = new Date()
  dates.setMonth(dates.getMonth() - num)
  var pastMonth = dates.getMonth() + 1
  var pastDay = dates.getDate()
  if (pastMonth >= 1 && pastMonth <= 9) {
    pastMonth = '0' + pastMonth
  }
  if (pastDay >= 0 && pastDay <= 9) {
    pastDay = '0' + pastDay
  }
  const endDate = dates.getFullYear() + '-' + pastMonth + '-' + pastDay;
  return endDate;
}
//获取当前时间指定天数
export function GetDayA(num) {
  const dates = new Date()
  dates.setDate(dates.getDate() - num)
  var pastMonth = dates.getMonth() + 1
  var pastDay = dates.getDate()
  if (pastMonth >= 1 && pastMonth <= 9) {
    pastMonth = '0' + pastMonth
  }
  if (pastDay >= 0 && pastDay <= 9) {
    pastDay = '0' + pastDay
  }
  const endDate = dates.getFullYear() + '-' + pastMonth + '-' + pastDay;
  return endDate;
}
//获取当前时间
export function GetMonB(num) {
  const loadYear = new Date().getFullYear()
  let loadMonth = new Date().getMonth() + 1
  let loadDay = new Date().getDate()
  if (loadMonth >= 1 && loadMonth <= 9) {
    loadMonth = '0' + loadMonth
  }
  if (loadDay >= 0 && loadDay <= 9) {
    loadDay = '0' + loadDay
  }
  const date = loadYear + '-' + loadMonth + '-' + loadDay
  return date;
}

